package dS.ProjectGPS.LeicaOWI;

import javax.microedition.lcdui.*;

public class FormOwi1SP_UTM extends Form implements FormOwi {
  OWIAgent owiAgent = null;

  TextField utmFalseOriginEast = new TextField("False Origin East (m)", "", 50,
                                               TextField.DECIMAL);
  TextField utmFalseOriginNorth = new TextField("False Origin North (m)", "",
                                                50, TextField.DECIMAL);
  TextField utmLatitudeOrigin = new TextField("Latitude Origin", "", 50,
                                              TextField.DECIMAL);
  TextField centralMeridian = new TextField("Central Meridian", "", 50,
                                            TextField.DECIMAL);
  TextField scaleOnCentralMeridian = new TextField("Scale on Central Meridian",
     "", 50, TextField.DECIMAL);

  public FormOwi1SP_UTM(OWIAgent o) {
    super("UTM");

    owiAgent = o;

    try {
      ndsInit();
    }
    catch (Exception ex) {
    }
  }

  public void ndsInit() throws Exception {
    append(utmFalseOriginEast);
    append(utmFalseOriginNorth);
    append(utmLatitudeOrigin);
    append(centralMeridian);
    append(scaleOnCentralMeridian);
  }

  public void update() {
    owiAgent.query(OWI.qs1SP());

    utmFalseOriginEast.setString(OWI.ospUtmFOEast);
    utmFalseOriginNorth.setString(OWI.ospUtmFONorth);
    utmLatitudeOrigin.setString(OWI.ospUtmLatOrigin);
    centralMeridian.setString(OWI.ospUtmCentralMeridian);
    scaleOnCentralMeridian.setString(OWI.ospUtmScale);
  }

  public void save() {

    String msgId = "1SP";

    // Setup SET parameters
    String[] outputs = {
                       msgId,
                       utmFalseOriginEast.getString(),
                       utmFalseOriginNorth.getString(),
                       utmLatitudeOrigin.getString(),
                       centralMeridian.getString(),
                       scaleOnCentralMeridian.getString(),

                       OWI.osp2dhRotX,
                       OWI.osp2dhRotY,
                       OWI.osp2dhShiftX,
                       OWI.osp2dhShiftY,
                       OWI.osp2dhRotation,
                       OWI.osp2dhScale,

                       OWI.ospHtOriginX, OWI.ospHtOriginY, OWI.ospHtP1,
                       OWI.ospHtP2, OWI.ospHtP3
    };

    //Send message and update form if successful
    int ackCode = (owiAgent.set(msgId, OWI.setMessage(outputs)));
    Controller.showACKAlert(this,this,ackCode);

  }

}
